package com.invengo.module_check.data.repsitory.common;

import com.invengo.library_db.entity.module_check.offline.UserBean;
import com.invengo.module_check.data.entity.FeatureBean;
import com.invengo.module_check.data.repsitory.common.source.CommonSource;
import com.invengo.module_check.data.repsitory.common.source.impl.HttpCommonSourceImpl;
import com.invengo.module_check.data.repsitory.common.source.impl.LocalCommonSourceImpl;

import java.util.ArrayList;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.bus.SourceUtils;
import me.goldze.mvvmhabit.http.BaseBean;

/**
 * 公共仓库，非业务相关的存储，数据调用操作
 */
public class CommonRepsitory extends BaseModel<CommonSource> implements CommonSource {

    private volatile static CommonRepsitory INSTANCE = null;

    public static CommonRepsitory getInstance() {
        if (INSTANCE == null) {
            synchronized (CommonRepsitory.class) {
                if (INSTANCE == null) {
                    INSTANCE = new CommonRepsitory();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 刷新源
     */
    @Override
    public void refreshSource() {
        source = SourceUtils.getSource(LocalCommonSourceImpl.class,HttpCommonSourceImpl.class);
    }

    @Override
    public Observable<BaseBean<UserBean>> checkLogin(String account, String password) {
        return source.checkLogin(account,password);
    }

    @Override
    public ArrayList<FeatureBean> getFeatureList() {
        return source.getFeatureList();
    }

    @Override
    public void saveLoginUser(String userName,String passWord,int UserId) {
        CommonSource.super.saveLoginUser(userName,passWord,UserId);
    }

    @Override
    public void cleanUser() {
        CommonSource.super.cleanUser();
    }
}
